<template>
	<view class="">
		<view class="zishi" v-if="!submitbol">
			<!-- 姓名 -->
			<view class="xm">
				<view class="xmm">
					<text><text style="color:red;">*</text>真实姓名</text>
				</view>
				<view class="inp">
					<u--input placeholder="请输入真实姓名" border="bottom" clearable v-model="value"
						@change="change"></u--input>
				</view>
			</view>
			<!-- 身份证号 -->
			<view class="xm">
				<view class="xmm">
					<text><text style="color:red;">*</text>身份证号</text>
				</view>
				<view class="inp">
					<u--input placeholder="请输入身份证号" border="bottom" clearable v-model="value2"
						@change="change2"></u--input>
				</view>
			</view>
			<u-gap height="20" bgColor="#ecfefd"></u-gap>
			<!-- 身份证正面 -->
			<text style="margin-top: 6px;"><text style="color:red;">*</text>上传身份证正反面</text>
			<view class="sfzm">
				<u-upload :fileList="fileList6" @afterRead="afterRead" @delete="deletePic" name="6" multiple
					:maxCount="1" width="250" height="150">
					<image src="/static/身份证正面.png" mode="widthFix" style="width: 185px;height: 150px;"></image>
				</u-upload>
			</view>
			<!-- 身份证背面 -->
			<view class="beim">

				<u-upload :fileList="fileList7" @afterRead="afterRead" @delete="deletePic" name="7" multiple
					:maxCount="1" width="250" height="150">
					<image src="/static/身份证背面.png" mode="widthFix" style="width: 250px;height: 150px;"></image>
				</u-upload>

			</view>

			<u-gap height="20" bgColor="#ecfefd"></u-gap>
			<!-- 健康证 -->
			<text style="margin-top: 6px;"><text style="color:red;">*</text>上传健康证</text>
			<view class="jk">
				<u-upload :fileList="fileList3" @afterRead="afterRead" @delete="deletePic" name="3" multiple
					:maxCount="1" :previewFullImage="true"></u-upload>
			</view>
			<!-- 提交 -->

			<view class="btnn" @click="submit">
				<u-button type="primary" text="确认提交"></u-button>
			</view>
		</view>
		<view class="nopass" v-else>
			<!-- 	{{examine}}
			{{pass}} -->
			<view class="" v-if="examine=='false'">
				<view class="nopass">
					<image :src="nopass" mode=""></image>
					<text>已提交管理员审核中~</text>
				</view>
			</view>

			<view class="" v-else>
				<view class="nopass" v-if="pass=='true'">
					<image :src="nopass3" mode=""></image>
					<text>{{suggestedModifications2}}</text>
				</view>
				<view class="nopass" v-else>
					<image :src="nopass2" mode=""></image>
					<text>没有通过:{{suggestedModifications}}</text>
					<button @click="updata">点击去修改</button>
				</view>
			</view>

		</view>
	</view>


</template>

<script>
	import {
		base_Url
	} from '../../../utils/Url';

	export default {
		data() {
			return {
				submitbol: false,

				nopass: base_Url + "/upload/已通过.png",
				nopass3: base_Url + "/upload/已提交.png",
				nopass2: base_Url + "/upload/未通过.png",
				examine: true,
				pass: false,
				suggestedModifications2: "已通过",
				suggestedModifications: "xxxxxx",
				value: '',
				value2: '',
				fileList6: [],
				fileList7: [],
				fileList3: [],
				id: ""

			}
		},
		mounted() {
			console.log("书法鉴赏", this.pass);
			// uni.setStorageSync("shbz", this.pass == 'true' ? true : false)
		},
		onLoad() {
			this.getUserinfo()

		},
		onPullDownRefresh() {
			uni.redirectTo({
				url: '/pages/my/qualificationApplication/qualificationApplication'
			})
		},
		methods: {
			getUserinfo() {
				const aa = uni.getStorageSync("userinfo")
				this.$http.post('/qualificationReview/queryByid', {

					userId: JSON.parse(aa).id,


				}).then(res => {
					console.log('res', res);
					uni.setStorageSync("yinhs", res.result)
					this.examine = res.result.examine
					this.suggestedModifications = res.result.suggestedModifications
					this.pass = res.result.pass
					this.submitbol = true

				})
			},
			climage(e) {

				let akk = []
				if (this[`fileList${e}`][0].type) {
					akk = this[`fileList${e}`].map(item => {
						console.log("数据", item);
						return {
							...item[0]
						}
					})
				} else {
					akk = this[`fileList${e}`]
				}
				return akk
			},
			submit() {
				console.log("提交");
				const aa = uni.getStorageSync("userinfo")
				console.log("useri", aa);
				console.log("sss", this.fileList6);
				console.log("sss1", this.fileList7);
				console.log("sss2", this.fileList3);
				// const aa2 = uni.getStorageSync("yinh")
				// console.log("xinxi", aa2.accountOpeningCertificate[0].uid);
				const aaa = this.climage(6)
				const aaa2 = this.climage(7)
				const aaa3 = this.climage(3)
				console.log("aaa", aaa);
				console.log("aaa2", aaa2);
				console.log("aaa3", aaa3);


				const data = {

					userId: JSON.parse(aa).id,
					name: this.value,
					identityCard: this.value2,
					identityCardFront: aaa,
					identityCardReverse: aaa2,
					healthCertificate: aaa3,
					id: this.id

				}
				console.log("评价的相关", data);

				this.$http.post("/qualificationReview/insert", data).then(res => {

					console.log("res", res.code);
					this.submitbol = true
					this.examine = 'false'
					if (res.code == 200) {
						this.$showMsg("成功", res)


						// this.$toPage()
					}
				})
			},
			updata() {
				const aa = uni.getStorageSync("yinhs")
				console.log("xinxi", aa);
				this.value = aa.name
				this.value2 = aa.identityCard

				this.id = aa.id
				this.fileList6 = aa.identityCardFront.map(item => {
					return {
						...item,
						url: item.url.replace(/^http:\/\/127\.0\.0\.1:8080/, base_Url)
					}
				})
				this.fileList7 = aa.identityCardReverse.map(item => {
					return {
						...item,
						url: item.url.replace(/^http:\/\/127\.0\.0\.1:8080/, base_Url)
					}
				})
				this.fileList3 = aa.healthCertificate.map(item => {
					return {
						...item,
						url: item.url.replace(/^http:\/\/127\.0\.0\.1:8080/, base_Url)
					}
				})
				// identityCardFront: aaa,
				// 	identityCardReverse: aaa2,
				// 	healthCertificate: aaa3,


				// this.fileList1 = aa.accountOpeningCertificate.map(item => {
				// 	return {
				// 		...item,
				// 		url: item.url.replace(/^http:\/\/127\.0\.0\.1:8080/, base_Url)
				// 	}
				// })
				this.submitbol = false
				// this.examine = false
			},
			change(e) {
				// console.log('change', e);
			},
			change2(e) {
				// console.log('change', e);
			},
			deletePic(event) {
				this[`fileList${event.name}`].splice(event.index, 1);
			},
			// 新增图片
			async afterRead(event) {
				console.log("啊大大", event.name);
				// 当设置 multiple 为 true 时, file 为数组格式，否则为对象格式
				let lists = [].concat(event.file);
				let fileListLen = this[`fileList${event.name}`].length;
				lists.map((item) => {
					this[`fileList${event.name}`].push({
						...item,
						status: "uploading",
						message: "上传中",
					});
				});
				for (let i = 0; i < lists.length; i++) {
					const result = await this.uploadFilePromise(lists[i].url);
					let item = this[`fileList${event.name}`][fileListLen];
					console.log("item", result);
					this[`fileList${event.name}`].splice(
						fileListLen,
						1,
						// Object.assign(item, {
						// 	...result,
						// 	status: "success"
						// })
						Object.assign(item, {
							...result,
							status: "success"
						})
					);
					fileListLen++;
				}
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: base_Url + "/common/upload", // 仅为示例，非真实的接口地址
						filePath: url,
						name: "file",
						formData: {
							user: "test",
						},
						success: (res) => {
							console.log("res", res);
							// setTimeout(() => {
							resolve(JSON.parse(res.data).result);
						},
					});
				});
			},
		}
	}
</script>

<style lang="scss">
	.nopass {

		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		margin-top: 50px;

		image {
			width: 100px;
			height: 100px;
		}
	}

	.zishi {
		padding: 8px;

		.xm {
			display: flex;
			justify-content: space-between;
			align-items: center;

			.xmm {
				// padding: 8px;
			}

			.inp {
				width: 68%;
				padding: 0px 18px;
			}
		}

		.sfzm,
		.beim {
			margin-top: 15px;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;
		}

		.btnn {}

	}
</style>